{use master_page('admin/v_master')} 
  
{block content}
<?php 
$cu_group = $this->usergroup_manager->get($this->current_user()->usergroup_id);  
?>
<script>
$(document).ready(function(){
	$('#type').change(function(){
		var v = $(this).val(); 
		<?
		$get_type = array_remove($_GET, 'type');
		$get_params = Array();
		foreach($_GET as $k=>$v)
		{
			$get_params[] = "$k=$v";
		}
		$get_params_str = implode('&',$get_params);
		?>
		var url = '<?=_U("page_class/index?")?><?=$get_params_str?>&type=' + v;
		//alert(url);
		//window.open(url);
		window.location.href = url ;  
	}) ;

	$("#chkall").click(function(){
		var checked = $(this).attr("checked");
		$(".datatable tbody input[type=checkbox]").attr("checked",checked) ;  
	}) ; 
	
})
</script>
<?php
$ci = &get_instance(); 
$ci->cu_group = $cu_group ;
$select_html = "<select id='parent_id' class='bind'><option value='0'>顶层</option>";
$ci->select_html = $select_html;
function bl_page_class($page_classes,$level=1)
{$ci = &get_instance(); 
$cu_group = $ci->cu_group ;
?>
	<?php foreach($page_classes as $page_class):
	$pad = "";
	if($level>1)
	{
		for($i=0;$i<$level-1;$i++)
		{
			$pad = $pad . "&nbsp;&nbsp;";
	}
	$pad = $pad."└";
	}
	if($level == 1){
		$pad="";
	}
	if(!empty($_GET['id'])):
	if($page_class->id!=$_GET['id']):
		$ci->select_html .= "<option value='$page_class->id'>$pad$page_class->title</option>";
	endif;
	else:
	$ci->select_html .= "<option value='$page_class->id'>$pad$page_class->title</option>";
	endif;
	?>
	<tr> 
		<td>
			<input type="checkbox" value="<?php echo $page_class->id;?>" name="ids[]">
		</td>
		<td align="center">
			<span style="width:59px" class="hotspot">
				<input type="text" name="listorder[<?php echo $page_class->id?>]" value="<?php echo $page_class->order?>" class="input_c">
			</span>
		</td>
		<td align="center" width="90">{page_class->id}</td> 
		<td style="text-align:left;padding-left:<?=$level*10?>px;" align="left"  width="200">
			└<a onmouseover="tooltip.show('点击显示该单页分类下的单页列表');" onmouseout="tooltip.hide();"
				href="<?php echo _U("page/index?tab=page_manager&class-id=".$page_class->id)?>" target="_blank">
				{page_class->title}
			</a>
		</td> 
		<td align="center" width="200"><?=$page_class->alias?></td>
		<td align="center" width="170">
			<?php if($cu_group->permission("page_class","edit")):?>
			<a class="edit" onmouseover="tooltip.show('编辑');" onmouseout="tooltip.hide();"  href="<?=_U('page_class/edit?tab=system_manager&id=')?>{page_class->id}">
			</a>
			<?php endif;?>
			<?php if($cu_group->permission("page_class","edit")):?>
			<a class="a_add_content" onmouseover="tooltip.show('添加子栏目');" onmouseout="tooltip.hide();"  href="<?=_U("page_class/edit?tab=system_manager&parent_id=$page_class->id")?>">
			</a>
			<?php endif;?>
			<?php if($cu_group->permission("page_class","del")):?>
			<a class="delete" onmouseover="tooltip.show('删除 ');" onmouseout="tooltip.hide();"  onclick="javascript:return confirm('删除单页分类将会删除分类下所属的单页，是否确认删除');" href="<?=_U('page_class/del?tab=system_manager&id=')?>{page_class->id}">
			</a>
			<?php endif;?>
		</td> 
	</tr>
	<?if(sizeof($page_class->children)>0){bl_page_class($page_class->children,$level+1);}?> 
	<?php endforeach;?>
<?php
}
?>
<form id = 'form1' action = '<?=$_SERVER['REQUEST_URI']?>' method='post'>
	<div class="blank20" style="height:10px;"></div>
	<?php if($cu_group->permission("page_class","edit")):?>
	<div style="padding-left:10px;">
		<input style="width:132px;height:38px;line-height:38px;color:white;background:url(images/btn_03.gif) left top no-repeat;border:none; text-align:center;
 			 cursor: pointer;" class="btn_c" type="button" value=" 添加分类 " 
 			 onclick="javascript:window.location.href='<?php echo _U("page_class/edit?tab=system_manager")?>'">
		<a style="color:red">* 注意:至少保留一个分类，id=1的分类无法删除</a>
	</div>
	<?php endif;?>
		<div class="blank5" style="height:10px;"></div>
	<div id="tagscontent" class="right_box">
	<table class="datatable" style='width:100%;'>
		<thead>
			<tr>
				<th >
					<input title="点击可全选本页的所有项目" type="checkbox" id="chkall">
				</th> 
				<th>排序</th>
				<th>ID<?=lang('page_class_id')?></th>
				<th><?=lang('page_class_title')?></th>
				<th><?=lang('page_class_alias')?></th>
				<th width="168">操作</th>
			</tr>
		</thead>
		<tbody>
		 
			<?php if($page_classes == null || sizeof($page_classes)==0):?>
			<tr><td colspan="6">&nbsp;</td></tr>
			<?php endif;?>
			<?php foreach($page_classes as $page_class):
			if(!empty($_GET['id'])):
			if($page_class->id!=$_GET['id']):
				$ci->select_html .= "<option value='$page_class->id'>$page_class->title</option>";
			endif;
			else:
				$ci->select_html .= "<option value='$page_class->id'>$page_class->title</option>";
			endif;
			?>
			<tr> 
				<td style="width:31px;">
					<input type="checkbox" value="<?php echo $page_class->id;?>"  name="ids[]">
				</td>
				<td align="center">
					<span style="width:59px" class="hotspot" >
						<input type="text" name="listorder[<?php echo $page_class->id?>]" value="<?php echo $page_class->order?>" class="input_c">
					</span>
				</td>
				<td align="center">{page_class->id}</td> 
				<td style="text-align:left;"align="left">
					<a onmouseover="tooltip.show('点击显示该单页分类下的单页列表');" onmouseout="tooltip.hide();"
						href="<?php echo _U("page/index?tab=page_manager&class-id=".$page_class->id)?>" target="_blank">
						{page_class->title}
					</a>
				</td> 
				<td align="center"><?=$page_class->alias?></td>
				<td align="center" >
					<?php if($cu_group->permission("page_class","edit")):?>
					<a class="edit" onmouseover="tooltip.show('编辑');" onmouseout="tooltip.hide();" href="<?=_U('page_class/edit?tab=system_manager&id=')?>{page_class->id}">
					</a>
					<?php endif;?>
					<?php if($cu_group->permission("page_class","edit")):?>
					<a  class="a_add_content" onmouseover="tooltip.show('添加子栏目');" onmouseout="tooltip.hide();" href="<?=_U("page_class/edit?tab=system_manager&parent_id=$page_class->id")?>">
					</a>
					<?php endif;?>
					<?php if($cu_group->permission("page_class","del")):?>
					<a class="delete" onmouseover="tooltip.show('删除');" onmouseout="tooltip.hide();" onclick="javascript:return confirm('删除单页分类将会删除分类下所属的单页，是否确认删除');" href="<?=_U('page_class/del?tab=system_manager&id=')?>{page_class->id}">
					</a>
					<?php endif;?>
				</td>
			</tr>
			<?if(sizeof($page_class->children)>0){bl_page_class($page_class->children,2);}?>
			<?php endforeach;$ci->select_html.="</select>"?> 
		</tbody>
	</table>
<div class="blank10" style="height:10px"></div>	
<script>
$(document).ready(function(){
	$('#btn_delete').click(function(){
		var frm = $("#form1");
		frm.attr('action','<?php echo _U("page_class/del");?>'); 
		frm.submit();
	});
	$('#btn_order').click(function(){
		var frm = $("#form1");
		frm.attr('action','<?php echo _U("page_class/order");?>'); 
		frm.submit();
	});

	$('#btn_moveto').click(function(){
		var frm = $("#form1");
		var id = $("#parent_id").val();
		if(id!="")
		{
			var url = '<?php echo _U("page_class/moveto/");?>' + id;
			frm.attr('action',url); 
			frm.submit();
		}
		else
		{
			alert("请选择移动到的分类") ;      
		}
	});
});
</script>
<?php if($cu_group->permission("page_class","del")):?>
<input class="btn_d" type="button" value=" 删除 " id="btn_delete">
<?php endif;?>
<?php if($cu_group->permission("page_class","order")):?>
<input class="btn_d" type="button" value=" 排序 " id="btn_order">
<?php endif;?>
<?php if($cu_group->permission("page_class","moveto")):?>
<input class="btn_e" type="button" value=" 移动到 " id="btn_moveto" >
	<?php echo $ci->select_html;?>
<?php endif;?>
	<script>
	/****
	var editor;
	KindEditor.ready(function(K) {
		editor = K.create('#content',{allowFileManager : true}) ;      
	});*****/        
	$(document).ready(function(){

		var tmp = $('input[name=p_target_window]').val();
		if(tmp != '_self' && tmp !='_blank' && tmp !='') 
		{
			$('#target_window option:eq(2)').attr('value',tmp);
			$('input[name=p_target_window]').css('display',''); 
			$('#target_window').val(tmp); 
		}
		$('#target_window').change(function(){
			var v = $(this).val();
			if(v=='custom')
			{
				$('input[name=p_target_window]').css('display','');
			}
			else
			{
				$('input[name=p_target_window]').css('display','none');
			}
			$('#target_window').change();
		});
	});
	</script>
	</div>
</form>

{end} 
